package com.zhangxin.designmode.designpattern.singleten;

import java.util.Objects;

/**
 * 双重检查锁 懒汉单例
 *
 * @author zhangxin
 * @date 2022/4/26
 */
public class Singleton3Demo {

    private static Singleton3Demo instance;

    public Singleton3Demo() {
    }

    public static Singleton3Demo getInstance() {
        if (Objects.isNull(instance)) {
            synchronized (Singleton3Demo.class) {
                if (Objects.isNull(instance)) {
                    return new Singleton3Demo();
                }
            }
        }
        return instance;
    }
}
